//
//  SettingViewController.m
//  parent
//
//  Created by yanzhen on 15/7/20.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "SettingViewController.h"
#import "AFAppClient.h"
#import "ModifyPasswordViewController.h"
#import "EditInfoViewController.h"
#import "UMFeedback.h"
#import "SDImageCache.h"
#import "Config.h"
#import "ApplyViewController.h"

@interface SettingViewController ()
@property (weak, nonatomic) IBOutlet UIButton *logOut;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navigationItem setTitle:@"设置"];
    [self CustomBackButton];
    self.logOut.layer.cornerRadius=25.0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)changePwd:(id)sender {
    ModifyPasswordViewController *pwd = [[ModifyPasswordViewController alloc]init];
    [self.navigationController pushViewController:pwd animated:YES];
}
- (IBAction)editInfo:(id)sender {
    EditInfoViewController *editInfo = [[EditInfoViewController alloc]init];
    [self.navigationController pushViewController:editInfo animated:YES];
}
- (IBAction)clearIt:(id)sender {
    [self showHud:@"清除中" isDim:YES];
    [self performSelectorOnMainThread:@selector(clearSDImageCache)
                           withObject:nil
                        waitUntilDone:YES];
    [self showHudComplete:@"清除成功" success:YES];
}
- (void)clearSDImageCache {
    
    [[SDImageCache sharedImageCache] clearDisk];
}
- (IBAction)feedBack:(id)sender {
//    [self.navigationController pushViewController:[UMFeedback feedbackViewController]
//                                         animated:YES];
    [self presentModalViewController:[UMFeedback feedbackModalViewController]
                            animated:YES];
}
- (IBAction)comment:(id)sender {
    NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", @"1039736339"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

- (IBAction)logout:(id)sender {
    BOOL isLogin = [Config Instance].isCookie;
    if(isLogin){
        [[Config Instance]saveUID:0];
        [Config Instance].isLogin = NO;
        [[Config Instance] saveCookie:NO];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"login" object:@"0"];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"" forKey:@"info"];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:kReloadInfo object:@YES];
        
        [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
           // [weakSelf hideHud];
            if (error && error.errorCode != EMErrorServerNotLogin) {
               // [weakSelf showHint:error.description];
            }
            else{
                [[ApplyViewController shareController] clear];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
            }
        } onQueue:nil];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
